define(['jquery', 'bootstrap','backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'staff/weekrecommend/index',
                    add_url: '',
                    edit_url: 'staff/weekrecommend/edit',
                    del_url: '',
                    multi_url: '',
                    table: 'page',
                }
            });

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'weight',
                columns: [
                    [
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'name', title: __('name'),editable:"input",operate: false},
                        {field: 'stafftype.zn_value', title: __('type'),operate:false},
                        {field: 'weight', title: __('weight'),operate:false},
                        {field: 'isrecommend', title: __('recommend'),  formatter: Table.api.formatter.status1},
                        {field: 'avatar', title: __('avatar'), formatter: Table.api.formatter.image, operate: false},
                        {field: 'birthday', title: __('birthday'),  operate:false},
                        {field: 'createtime', title: __('createtime'),  operate:false},
                        {field: 'operate', title: __('Operate'), events: Controller.api.events.operate, formatter: Controller.api.formatter.operate}
                    ]
                ],
                //普通搜索
                commonSearch: false,
                searchFormVisible: false,
                titleForm: '', //为空则不显示标题，不定义默认显示：普通搜索
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            //刷新表单
            $(document).on("click", ".btn-refreshpic", function () {
                table.bootstrapTable('refresh');
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        addworklog: function () {
            Controller.api.bindevent();
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                operate: function (value, row, index) {
                    //返回字符串加上Table.api.formatter.operate的结果
                    //默认需要按需显示排序/编辑/删除按钮,则需要在Table.api.formatter.operate将table传入
                    //传入了table以后如果edit_url为空则不显示编辑按钮,如果del_url为空则不显显删除按钮
                    return Table.api.formatter.operate(value, row, index, $("#table"));
                },
            },
            events: {
                operate: $.extend( Table.api.events.operate)
            }
        }
    };
    return Controller;
});